package com.jianguozh.difs.framework.constant.enums;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonValue;
import com.jianguozh.difs.framework.annotation.EnumDesc;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 日志类型枚举
 *
 * @author hanrs
 * @email 4076130@qq.com
 * @since 2022/6/9 17:33
 */
@EnumDesc(title = "日志类型")
//@JsonFormat(shape = JsonFormat.Shape.OBJECT)
@Getter
@AllArgsConstructor
public enum LogTypeEnum implements IEnum<String> {

    NORMAL("0", "正常日志"), ERROR("9", "错误日志");

    @JsonValue
    private final String value;
    private final String displayName;

    /**
     * 根据名称获取枚举
     *
     * @param value value
     * @return
     */
    @JsonCreator
    public static LogTypeEnum fromValue(String value) {
        if (StrUtil.isNotBlank(value)) {
            for (LogTypeEnum item : LogTypeEnum.values()) {
                if (value.equals(item.getValue())) {
                    return item;
                }
            }
        }
        return null;
    }
}
